import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

dfuserpoint=pd.read_excel('发票重新验证.xlsx')
#dfuserpoint=pd.read_csv('发票识别导出-筛选.csv')

outpd = pd.DataFrame(dfuserpoint,columns=['大单号','主店片区','主店号','主店名','主店所在公司','现金','公司礼券','商场储值','订金销账','积分抵现','商场礼券','活动名称','日期','银行卡','小票网址'])
outpd.insert(loc=15,column='result',value='')


import requests

url_heard = "http://192.168.2.121:8030/v1/Sales/RecalibrationImageListForSaleBig?CheckCode=RCheck&BigNo="


def recheck_receipt(bigno):
    headers = {'Connection': 'close'}
    req = requests.get(url=url_heard+bigno.upper(), headers=headers)
    re = req.text
    req.close()
    return re


for index, row in outpd.iterrows():
    if not isinstance(row['大单号'], str) or len(row['大单号'])<=1:
        outpd.iloc[index, outpd.columns.get_loc("result")] = ''
        continue
    print(row['大单号'])
    result = recheck_receipt(row['大单号'])
    print(index,result)
    outpd.iloc[index, outpd.columns.get_loc("result")] = result

with pd.ExcelWriter('out-发票重新验证.xlsx') as writer:
    outpd.to_excel(writer, sheet_name='Sheet1')
